package com.design.pattern.creational.prototype.destorySingleton;

import com.design.pattern.creational.singleton.HungrySingleton;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * description
 *
 * @author RenQiQiang 2019/03/31 15:27
 */
public class Test {

    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        HungrySingleton singleton = HungrySingleton.getInstance();

        Method method = HungrySingleton.class.getDeclaredMethod("clone");
        method.setAccessible(true);
        HungrySingleton clone = (HungrySingleton) method.invoke(singleton);
        System.out.println(singleton);
        System.out.println(clone);
        //要么不实现cloneable
        //要么重写clone 调用getinstance()
    }
}
